package com.icity.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.icity.entity.Retentions;
import com.icity.entity.system.TableSupport;
import com.icity.mapper.RementionStatisticalMapper;
import com.icity.service.RementionStatisticalService;

@Service
public class RementionStatisticsServiceImpl implements RementionStatisticalService{

	@Autowired
	private RementionStatisticalMapper rementionStatisticalMapper;

	@Override
	public TableSupport<?> getRementionList(Map<Object, Object> map) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		TableSupport<Retentions> listTable = new TableSupport<Retentions>();
		List<Retentions> listRetentions = rementionStatisticalMapper.selectRetention(map);
		for(Retentions retentions : listRetentions){
			retentions.setDateCn(sdf.format(retentions.getDate()));
			if(retentions.getOne()!=null & !retentions.getOne().equals("")){
				retentions.setOne(retentions.getOne()+"%");
			}
			if(retentions.getTwo()!=null && !retentions.getTwo().equals("null")){
				retentions.setTwo(retentions.getTwo()+"%");
			}
			if(retentions.getThree()!=null && !retentions.getThree().equals("null")){
				retentions.setThree(retentions.getThree()+"%");
			}
			if(retentions.getFour()!=null && !retentions.getFour().equals("null")){
				retentions.setFour(retentions.getFour()+"%");
			}
			if(retentions.getFive()!=null && !retentions.getFive().equals("null")){
				retentions.setFive(retentions.getOne()+"%");
			}
			if(retentions.getSix()!=null && !retentions.getSix().equals("null")){
				retentions.setSix(retentions.getSix()+"%");
			}
			if(retentions.getSeven()!=null && !retentions.getSeven().equals("null")){
				retentions.setSeven(retentions.getSeven()+"%");
			}
			if(retentions.getFourteen()!=null && !retentions.getFourteen().equals("null")){
				retentions.setFourteen(retentions.getFourteen()+"%");
			}
			if(retentions.getThrity()!=null && !retentions.getThrity().equals("null")){
				retentions.setThrity(retentions.getThrity()+"%");
			}
		}
		int count = rementionStatisticalMapper.selectRetentionCount(map);
		listTable.setCode(0);
		listTable.setMsg(null);
		listTable.setCount(count);
		listTable.setData(listRetentions);
		return listTable;
	}

}
